$(function () {
    $.post("/user/getUser",null,function (info) {
        var obj = JSON.parse(info);
        if(obj == null){
            location.href="/html/login.html"
        }
    });
    findAll(1);
})

function findAll(pageNO) {
    $.post("/order/findAllByItem","pageNO="+pageNO+"&"+$("#f1").serialize(),function (orderList) {
        var str = "";
        for(var i=0;i<orderList.list.length;i++){
            var obj = orderList.list[i];
            str += `<tr><td>${obj.id}</td>
                    <td>${obj.price}</td>
                    <td>${obj.state}</td>
                    <td>${obj.createDate}</td>
                    <td><a class="layui-btn layui-btn-normal" 
                      href="/html/manager/orderInfo.html?id=${obj.id}">查看详情</a></td></tr>`;
        }
        $("#orderData").html(str);

        if(pageNO == 1){
            layui.use('laypage', function(){
                var laypage = layui.laypage;
                //执行一个laypage实例
                laypage.render({
                    elem: 'cutPageDiv', //注意，这里的 test1 是 ID，不用加 # 号
                    count: orderList.total, //数据总数，从服务端得到
                    limit:orderList.pageSize,
                    jump:function (obj,first) {
                        if(!first){
                            findAll(obj.curr)
                        }
                    }
                })
            })
        };
    })
}